﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>系统参数添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
</head>
<body>
    <span style="margin-top:15px;margin-left:15px">
        <xblock>
            <button class="layui-btn" onclick="saveData()"><i class="layui-icon"></i>保存</button>
            <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
        </xblock>
    </span>

    <div style="margin: 20px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">

            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    参数类型
                </label>
                <div class="layui-input-inline">
                    <select name="partype" id="partype" >
                        <option value="">请选择</option>
                    </select>
                </div>

         
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    参数编码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="parCode" name="parCode" required="" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    参数名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="parName" name="parName" required="" autocomplete="off" class="layui-input">
                    <input type="hidden" id="id" name="id">
                </div>
        
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="L_email" class="layui-form-label">
                    参数值
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入参数内容" id="parValue" name="parValue" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="L_email" class="layui-form-label">
                  参数备注
                </label>
                <div class="layui-input-block">
                    <input type="text" id="memo" name="memo" required="" autocomplete="off" class="layui-input">
                </div>

            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    参数状态
                </label>
                <div class="layui-input-inline">
                    <select name="enable" id="enable"></select>
                </div>


            </div>
        </form>

    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var dataId = getUrlVariable("dataId");
        DictionaryDropDown("sp", "partype", "");
        DictionaryDropDown("ps", "enable", "open");

      if (dataId != "0") {
          $("input[ name='id']").val(dataId);
          loadData(dataId);
      }
 
    });

    // 保存数据
    function saveData() {
        $.ajax({
            url: "../System/savePar",
            data: { datas: JSON.stringify(FormToJson("AddForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var id = $("input[ name='id']").val();
                    var msg = "信息修改成功";
                    if (id == "0" || id == "") {
                        msg = "信息添加成功";
                    }
                    layer.alert(msg, { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

    //加载数据信息
    function loadData(parCode) {
        $.ajax({
            url: "../System/getParameterByCode",
            type: "post",
            data: {parCode:parCode},
            success: function (data) {
                if (data.Result) {
                    $.each(data.Data[0], function (name, value) {
                        if (name == "partype" || name == "enable") {
                            $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                      
                    });
                    $("#parValue").html(data.Data[0]["parValue"]);
              
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });

    }
</script>